home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / portmap_2.shar / diffs_wrt_bsd < prev    next >
Encoding:
Text File  |  1992-07-06  |  6.1 KB  |  257 lines

  1. *** portmap.c.bsd    Sun May  3 22:39:52 1992
  2. --- portmap.c    Thu Jun  4 23:16:36 1992
  3. ***************
  4. *** 83,99 ****
  5.   #include <rpc/rpc.h>
  6.   #include <rpc/pmap_prot.h>
  7.   #include <stdio.h>
  8. - #include <stdlib.h>
  9. - #include <string.h>
  10.   #include <syslog.h>
  11. - #include <unistd.h>
  12.   #include <netdb.h>
  13.   #include <sys/socket.h>
  14.   #include <sys/ioctl.h>
  15.   #include <sys/wait.h>
  16.   #include <sys/signal.h>
  17.   #include <sys/resource.h>
  18.   
  19.   void reg_service();
  20.   void reap();
  21.   static void callit();
  22. --- 83,115 ----
  23.   #include <rpc/rpc.h>
  24.   #include <rpc/pmap_prot.h>
  25.   #include <stdio.h>
  26.   #include <syslog.h>
  27.   #include <netdb.h>
  28.   #include <sys/socket.h>
  29.   #include <sys/ioctl.h>
  30.   #include <sys/wait.h>
  31.   #include <sys/signal.h>
  32. + #include <sys/time.h>
  33.   #include <sys/resource.h>
  34. + #ifdef SYSV40
  35. + #include <netinet/in.h>
  36. + #endif
  37.   
  38. + extern char *strerror();
  39. + extern char *malloc();
  40. + #ifndef LOG_PERROR
  41. + #define LOG_PERROR 0
  42. + #endif
  43. + #ifndef LOG_DAEMON
  44. + #define LOG_DAEMON 0
  45. + #endif
  46. + #ifndef svc_getcaller        /* SYSV4 */
  47. + #  define svc_getcaller svc_getrpccaller
  48. + #endif
  49.   void reg_service();
  50.   void reap();
  51.   static void callit();
  52. ***************
  53. *** 101,106 ****
  54. --- 117,124 ----
  55.   int debugging = 0;
  56.   extern int errno;
  57.   
  58. + #include "pmap_check.h"
  59.   main(argc, argv)
  60.       int argc;
  61.       char **argv;
  62. ***************
  63. *** 130,136 ****
  64.       }
  65.   
  66.       openlog("portmap", debugging ? LOG_PID | LOG_PERROR : LOG_PID,
  67. !         LOG_DAEMON);
  68.   
  69.       if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  70.           syslog(LOG_ERR, "cannot create udp socket: %m");
  71. --- 148,154 ----
  72.       }
  73.   
  74.       openlog("portmap", debugging ? LOG_PID | LOG_PERROR : LOG_PID,
  75. !         FACILITY);
  76.   
  77.       if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  78.           syslog(LOG_ERR, "cannot create udp socket: %m");
  79. ***************
  80. *** 182,187 ****
  81. --- 200,207 ----
  82.   
  83.       (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
  84.   
  85. +     /* additional initializations */
  86. +     check_startup();
  87.       (void)signal(SIGCHLD, reap);
  88.       svc_run();
  89.       syslog(LOG_ERR, "run_svc returned unexpectedly");
  90. ***************
  91. *** 238,243 ****
  92. --- 258,265 ----
  93.           /*
  94.            * Null proc call
  95.            */
  96. +         /* remote host authorization check */
  97. +         check_default(svc_getcaller(xprt), rqstp->rq_proc, (u_long) 0);
  98.           if (!svc_sendreply(xprt, xdr_void, (caddr_t)0) && debugging) {
  99.               abort();
  100.           }
  101. ***************
  102. *** 250,255 ****
  103. --- 272,283 ----
  104.           if (!svc_getargs(xprt, xdr_pmap, ®))
  105.               svcerr_decode(xprt);
  106.           else {
  107. +             /* reject non-local requests, protect priv. ports */
  108. +             if (!check_setunset(svc_getcaller(xprt), 
  109. +                 rqstp->rq_proc, reg.pm_prog, reg.pm_port)) {
  110. +                 ans = 0;
  111. +                 goto done;
  112. +             } 
  113.               /*
  114.                * check to see if already used
  115.                * find_service returns a hit even if
  116. ***************
  117. *** 299,304 ****
  118. --- 327,336 ----
  119.               svcerr_decode(xprt);
  120.           else {
  121.               ans = 0;
  122. +             /* reject non-local requests */
  123. +             if (!check_setunset(svc_getcaller(xprt), 
  124. +                 rqstp->rq_proc, reg.pm_prog, (u_long) 0))
  125. +                 goto done;
  126.               for (prevpml = NULL, pml = pmaplist; pml != NULL; ) {
  127.                   if ((pml->pml_map.pm_prog != reg.pm_prog) ||
  128.                       (pml->pml_map.pm_vers != reg.pm_vers)) {
  129. ***************
  130. *** 308,313 ****
  131. --- 340,353 ----
  132.                       continue;
  133.                   }
  134.                   /* found it; pml moves forward, prevpml stays */
  135. +                 /* privileged port check */
  136. +                 if (!check_privileged_port(svc_getcaller(xprt), 
  137. +                     rqstp->rq_proc, 
  138. +                     reg.pm_prog, 
  139. +                     pml->pml_map.pm_port)) {
  140. +                     ans = 0;
  141. +                     break;
  142. +                 }
  143.                   ans = 1;
  144.                   t = (caddr_t)pml;
  145.                   pml = pml->pml_next;
  146. ***************
  147. *** 332,337 ****
  148. --- 372,384 ----
  149.           if (!svc_getargs(xprt, xdr_pmap, ®))
  150.               svcerr_decode(xprt);
  151.           else {
  152. +             /* remote host authorization check */
  153. +             if (!check_default(svc_getcaller(xprt), 
  154. +                 rqstp->rq_proc, 
  155. +                 reg.pm_prog)) {
  156. +                 ans = 0;
  157. +                 goto done;
  158. +             }
  159.               fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot);
  160.               if (fnd)
  161.                   port = fnd->pml_map.pm_port;
  162. ***************
  163. *** 352,359 ****
  164.           if (!svc_getargs(xprt, xdr_void, NULL))
  165.               svcerr_decode(xprt);
  166.           else {
  167.               if ((!svc_sendreply(xprt, xdr_pmaplist,
  168. !                 (caddr_t)&pmaplist)) && debugging) {
  169.                   (void) fprintf(stderr, "svc_sendreply\n");
  170.                   abort();
  171.               }
  172. --- 399,414 ----
  173.           if (!svc_getargs(xprt, xdr_void, NULL))
  174.               svcerr_decode(xprt);
  175.           else {
  176. +             /* remote host authorization check */
  177. +             struct pmaplist *p;
  178. +             if (!check_default(svc_getcaller(xprt), 
  179. +                 rqstp->rq_proc, (u_long) 0)) {
  180. +                 p = 0;    /* send empty list */
  181. +             } else {
  182. +                 p = pmaplist;
  183. +             }
  184.               if ((!svc_sendreply(xprt, xdr_pmaplist,
  185. !                 (caddr_t)&p)) && debugging) {
  186.                   (void) fprintf(stderr, "svc_sendreply\n");
  187.                   abort();
  188.               }
  189. ***************
  190. *** 372,377 ****
  191. --- 427,434 ----
  192.           break;
  193.   
  194.       default:
  195. +         /* remote host authorization check */
  196. +         check_default(svc_getcaller(xprt), rqstp->rq_proc, (u_long) 0);
  197.           svcerr_noproc(xprt);
  198.           break;
  199.       }
  200. ***************
  201. *** 499,504 ****
  202. --- 556,565 ----
  203.       timeout.tv_usec = 0;
  204.       a.rmt_args.args = buf;
  205.       if (!svc_getargs(xprt, xdr_rmtcall_args, &a))
  206. +         return;
  207. +     /* host and service access control */
  208. +     if (!check_callit(svc_getcaller(xprt), 
  209. +         rqstp->rq_proc, a.rmt_prog, a.rmt_proc))
  210.           return;
  211.       if ((pml = find_service(a.rmt_prog, a.rmt_vers,
  212.           (u_long)IPPROTO_UDP)) == NULL)
  213. *** daemon.c.bsd    Sun May  3 22:45:10 1992
  214. --- daemon.c    Sat May 23 16:38:02 1992
  215. ***************
  216. *** 35,44 ****
  217.   static char sccsid[] = "@(#)daemon.c    5.3 (Berkeley) 12/28/90";
  218.   #endif /* LIBC_SCCS and not lint */
  219.   
  220. ! #include <sys/fcntl.h>
  221. ! #include <unistd.h>
  222. ! #include <paths.h>
  223.   
  224.   daemon(nochdir, noclose)
  225.       int nochdir, noclose;
  226.   {
  227. --- 35,50 ----
  228.   static char sccsid[] = "@(#)daemon.c    5.3 (Berkeley) 12/28/90";
  229.   #endif /* LIBC_SCCS and not lint */
  230.   
  231. ! #include <fcntl.h>
  232.   
  233. + /* From unistd.h */
  234. + #define STDIN_FILENO    0
  235. + #define STDOUT_FILENO    1
  236. + #define STDERR_FILENO    2
  237. + /* From paths.h */
  238. + #define _PATH_DEVNULL    "/dev/null"
  239.   daemon(nochdir, noclose)
  240.       int nochdir, noclose;
  241.   {
  242. ***************
  243. *** 62,65 ****
  244. --- 68,72 ----
  245.                   (void) close(devnull);
  246.           }
  247.       }
  248. +     return(0);
  249.   }
  250.